<template>
	<!-- 按钮 -->
	<div class="my-button-img-box" @click="onClick">
		<image class="my-button-img" src="/static/start-bt-bg.png" mode="scaleToFill" >
		</image>
		
		<div style="width: 100%;height: 100%; display: flex;align-items: center;justify-content: center;">
			<!-- 文字 -->
			<div class="my-button-text">
				{{text}}
			</div>
		</div>
	</div>
</template>

<script>
	export default {
		props: {
			text: {
				type: String,
				default: '按钮'
			},
		},
		data() {
			return {
				// 点击音效
				audioCtx: null,
			}
		},
		mounted() {
			// 初始化音效上下文
			const audioCtx = uni.createInnerAudioContext();
			audioCtx.volume = 0.2;
			//循环
			audioCtx.loop = false;
			// 自动播放，浏览器中可能不允许自动播放，需要手动触发
			audioCtx.autoplay = false;
			// 设置音频播放模式
			audioCtx.sessionCategory = "ambient";
			audioCtx.src = uni.envConfig.audios.click;
			this.audioCtx = audioCtx;
		},
		methods: {
			onClick(){
				this.audioCtx && this.audioCtx.play();
				this.$emit('click');
			},
		},
	}
</script>

<style scoped>
	.my-button-img-box{
		width: auto;
		height: auto;
		min-width: 400rpx;
		min-height: 90rpx;
		position: relative;
		text-align: center;
		padding: 0 120rpx;
		box-sizing: border-box;
	}
	.my-button-img-box:active{
		transform: scale(1.1);
	}
	.my-button-img{
		width: 100%;
		height: 100%;
		position: absolute;
		top:0;
		left: 0;
		z-index: -1;
	}
	.my-button-text{
		z-index: 9;
		color: #ffe6be;
		font-weight: bold;
		font-size: 36rpx;
		text-align: center;
		letter-spacing: 8rpx;
		word-wrap: break-word;
	}
</style>
